package com.ruoyi.file.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.file.domain.UserFileRole;
import com.ruoyi.file.service.IUserFileRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户文档权限Controller
 * 
 * @author zhangxiliang
 * @date 2021-11-04
 */
@RestController
@RequestMapping("/file/userrole")
public class UserFileRoleController extends BaseController
{
    @Autowired
    private IUserFileRoleService userFileRoleService;

    /**
     * 查询用户文档权限列表
     */
    @PreAuthorize("@ss.hasPermi('file:userrole:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserFileRole userFileRole)
    {
        startPage();
        List<UserFileRole> list = userFileRoleService.selectUserFileRoleList(userFileRole);
        return getDataTable(list);
    }

    /**
     * 导出用户文档权限列表
     */
    @PreAuthorize("@ss.hasPermi('file:userrole:export')")
    @Log(title = "用户文档权限", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserFileRole userFileRole)
    {
        List<UserFileRole> list = userFileRoleService.selectUserFileRoleList(userFileRole);
        ExcelUtil<UserFileRole> util = new ExcelUtil<UserFileRole>(UserFileRole.class);
        return util.exportExcel(list, "用户文档权限数据");
    }

    /**
     * 获取用户文档权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('file:userrole:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return AjaxResult.success(userFileRoleService.selectUserFileRoleByRoleId(roleId));
    }

    /**
     * 新增用户文档权限
     */
    @PreAuthorize("@ss.hasPermi('file:userrole:add')")
    @Log(title = "用户文档权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserFileRole userFileRole)
    {
        return toAjax(userFileRoleService.insertUserFileRole(userFileRole));
    }

    /**
     * 修改用户文档权限
     */
    @PreAuthorize("@ss.hasPermi('file:userrole:edit')")
    @Log(title = "用户文档权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserFileRole userFileRole)
    {
        return toAjax(userFileRoleService.updateUserFileRole(userFileRole));
    }

    /**
     * 删除用户文档权限
     */
    @PreAuthorize("@ss.hasPermi('file:userrole:remove')")
    @Log(title = "用户文档权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(userFileRoleService.deleteUserFileRoleByRoleIds(roleIds));
    }
}
